package com.yndsoft.jc.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
	// 数据库
	private static final String DATABASE_NAME = "HMC.db";
	// 菜品类别表
	public static final String XFRMS_DISHTYPE = "XFRMS_DISHTYPE";
	// 菜单表
	public static final String XFRMS_DISH = "XFRMS_DISH";
	// 购物车
	public static final String XFRMS_CART = "XFRMS_CART";
	// 购物车明细
	public static final String XFRMS_CARTITEM = "XFRMS_CARTITEM";
	// 数据库版本
	public static final int VERSION = 7;

	public DBHelper(Context context) {
		super(context, DATABASE_NAME, null, VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// 菜品类别表
		db.execSQL("CREATE TABLE IF NOT EXISTS " + XFRMS_DISHTYPE + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + " dt_id INTEGER NOT NULL, " + " dt_pid INTEGER NOT NULL, " + " dt_name TEXT NOT NULL) ");
		// 菜单表
		db.execSQL("CREATE TABLE IF NOT EXISTS " + XFRMS_DISH + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + " d_id INTEGER NOT NULL, " + " d_name TEXT NOT NULL, " + " dt_id INTEGER NOT NULL, " + " d_price TEXT NOT NULL, " + " d_state INTEGER NOT NULL, " + " d_printer INTEGER NOT NULL) ");
		// 购物车表
		db.execSQL("CREATE TABLE IF NOT EXISTS " + XFRMS_CART + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + " c_tableid INTEGER NOT NULL, " + " c_peoplenum INTEGER NOT NULL, " + " c_dishnum TEXT NOT NULL, " + " c_price TEXT NOT NULL, " + " c_demand TEXT NOT NULL) ");
		// 购物车明细表
		db.execSQL("CREATE TABLE IF NOT EXISTS " + XFRMS_CARTITEM + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + " ci_cartid INTEGER NOT NULL, " + " ci_dishid INTEGER NOT NULL, " + " ci_dishname TEXT NOT NULL, " + " ci_dishprice TEXT NOT NULL, " + " ci_dishnum TEXT NOT NULL) ");
		// db.execSQL("insert into XFRMS_WEBCONFIG(wc_name, wc_value) values(?,?)",
		// new Object[] { "IP", "http://192.168.0.104:9091/" });
		db.execSQL("insert into XFRMS_WEBCONFIG(wc_name, wc_value) values(?,?)", new Object[] { "IP", "http://dian.huishanlife.com/" });
		//db.execSQL("insert into XFRMS_WEBCONFIG(wc_name, wc_value) values(?,?)", new Object[] { "Print", "http://121.40.136.205:9091/" });
		db.execSQL("insert into XFRMS_WEBCONFIG(wc_name, wc_value) values(?,?)", new Object[] { "Print", "http://192.168.0.103:9099/" });
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + XFRMS_DISHTYPE);
		db.execSQL("DROP TABLE IF EXISTS " + XFRMS_DISH);
		db.execSQL("DROP TABLE IF EXISTS " + XFRMS_CART);
		db.execSQL("DROP TABLE IF EXISTS " + XFRMS_CARTITEM);
		onCreate(db);
	}
}
